#include <stdio.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#if defined(__linux__)
#define SLEEP usleep
#define MILLIS 1000
#elif defined(__APPLE__)
#define SLEEP usleep
#define MILLIS 1000
#include <unistd.h>
#elif defined(_WIN32)
#include <Windows.h>
#define SLEEP Sleep
#define MILLIS 1
#endif
void clear_screen()
{
#ifdef _WIN32
system("cls");
#else
system("clear");
#endif
}
double meanImage(uint32_t * Img, uint16_t NPixel)
{
int i=0;
double res =0.0;
for(i=0;i<NPixel;i++)
res+= (double)Img[i];
return res/(double)NPixel;
}
void AccHist(uint32_t* HistIn, uint32_t* HistOut, int Npixel)
{
for (int i = 0; i < 4096; i++)
{
for (int j = 0; j < Npixel; j++)
{
HistOut[i] += *(HistIn + j * 4096 + i);
}
}
}
{
printf(" acquisitionTime = %.1f s\n", acquisitionTime);
printf(" capturedFrameCount = %lld\n", capturedFrameCount);
printf(" decodedFrameCount = %lld\n", decodedFrameCount);
printf("deviceRamUsageBytes = %.1f MB\n", deviceRamUsageBytes * 1e-6);
printf(" downloadedBytes = %.1f MB\n", downloadedBytes * 1e-6);
printf(" dl rate = %.1f MB/s\n", 1e-6 * (downloadedBytes / acquisitionTime));
printf(" hostAllocatedBytes = %.1f MB\n", hostAllocatedBytes * 1e-6);
}
int main(void)
{
uint32_t* CntsBuf;
uint32_t* HistBuf;
uint32_t* AccHistBuf;
int pattern[10];
int device_count = 0, dev_num, nPixel, loop = 1;
uint64_t num;
uint32_t total;
char c = 0;
double maxFrameStartFrequency, extStartFreq, extGateFreq, extTrigFreq, average;
char *menu_strings[] = {
"Live counting mode: write on stdout an image",
"Live timing mode: write on stdout an histogram",
"Acquisition timing mode: get time tagging, frames and histogram",
"Holdoff: mean number of photons at different holdoff values",
"Save settings to file",
"Load settings from file",
"Configure outputs",
"Acquire with external start",
"Acquire with external gate and aux-input timetagging",
"Use external trigger",
"Load raw data from file"
};
printf("\n*******************************************************************************\n");
printf(" CRONO SDK Example\n");
printf("*******************************************************************************\n");
printf("Found %d CRONO devices: \n", device_count);
for (int d = 0; d < device_count; d++) {
printf("%d: %s\n", d+1, serial);
}
printf("\nChoose a device:\n");
scanf("%d", &dev_num);
getchar();
if (!err) {
printf("\nSUCCESSFUL!\nCamera with serial number %s Opened.\n", serial);
}
else {
printf("Error %i !\n", err);
return -1;
}
{
printf("Sensor Type: Crono 8x8\n");
nPixel = 64;
break;
printf("Sensor Type: Crono 128x1\n");
nPixel = 128;
break;
default:
printf("Error, invalid sensor type\n");
return -1;
}
CntsBuf = (uint32_t*)calloc(nPixel, sizeof(uint32_t));
HistBuf = (uint32_t*)calloc(4096 * nPixel, sizeof(uint32_t));
AccHistBuf = (uint32_t*)calloc(4096, sizeof(uint32_t));
pattern[0] = 0;
pattern[1] = 700;
if (err != 0)
{
loop = 0;
printf("Configuration error!");
}
while (loop) {
printf("\n*******************************************************************************\n");
printf(" Choose an option\n");
printf("*******************************************************************************\n");
for (int i = 0; i < sizeof(menu_strings) / sizeof(char*); i++) {
printf("\t%c) %s\n", i + 'a', menu_strings[i]);
}
printf("\tq) Quit\n> ");
c = getchar();
getchar();
if (c >= 'a' && c <= 'a' + sizeof(menu_strings) / sizeof(char*) - 1) {
printf("*******************************************************************************\n");
printf("%s\n", menu_strings[c - 'a']);
printf("*******************************************************************************\n");
}
switch (c)
{
case 'a':
dataIsNew = 0;
while (!dataIsNew)
{
SLEEP(10);
}
printf("Acquired counts per pixel:\n");
for (int i = 0; i < nPixel; i++)
{
printf("%d\n", *(CntsBuf + i));
}
printf("\n\tAcquisition status:\n");
print_status(status);
break;
case 'b':
dataIsNew = 0;
while (!dataIsNew)
{
SLEEP(10);
}
total = 0;
for (int j = 0; j < nPixel; j++)
total += CntsBuf[j];
printf("\nTotal events in frame: %d\n", total);
total = 0;
AccHist(HistBuf, AccHistBuf, nPixel);
for (int j = 0; j < 4094; j++)
total += AccHistBuf[j];
printf("\nTotal events in histogram: %d\n", total);
printf("Accumulated histogram for all pixels:");
for (int i = 0; i < 4096; i++)
{
printf("%d\n", *(AccHistBuf + i));
}
printf("\n\tAcquisition status:\n");
print_status(status);
break;
case 'c':
{
SLEEP(100);
if (!err)
{
clear_screen();
printf(" **********************\n");
printf(" * Acquisition status *\n");
printf(" **********************\n");
print_status(status);
}
else
printf("\nError %d", err);
}
SLEEP(1000);
free(AccHistBuf);
AccHistBuf = (uint32_t*)calloc(4096, sizeof(uint32_t));
total = 0;
{
if (num != 1)
break;
AccHist(HistBuf, AccHistBuf, nPixel);
}
for (int j = 0; j < 4096; j++)
total += AccHistBuf[j];
printf("\nTotal events in histogram: %d\n", total);
break;
case 'd':
for (int h = 50; h < 151; h = h + 50)
{
printf("\n ** Deadtime %d ns **\n", h);
{
SLEEP(100);
}
print_status(status);
if (num != 1)
break;
average = meanImage(CntsBuf, nPixel);
printf("\nAverage counts: %.2f at %d ns deadtime\n\n", average,h);
printf("-----------------------------------------\n");
}
break;
case 'e':
if (err)
{
printf("\nCannot save settings!\n");
break;
}
printf("\nSettings saved to file crono_example.ccf\n");
break;
case 'f':
printf(
"\nActual deadtime: %d ns\n", settings.
deadTimeNs);
if (err)
{
printf("\nCannot load settings!\n");
break;
}
printf("\nSettings loaded from file crono_example.ccf\n");
printf(
"\nLoaded deadtime: %d ns\n", settings.
deadTimeNs);
break;
case 'g':
pattern[0] = 50;
pattern[1] = 10;
pattern[0] = 0;
pattern[1] = 200;
printf("Acquisition will now start and run for 10s.\n\n");
printf("Output 1 is configured for laser sync: 50ns off, 10ns on.\n");
printf("Output 2 is configured for start sync at %3f MHz.\n", maxFrameStartFrequency*1e-6);
printf("Output 3 is configured for gate: 0ns off, 200ns on.\n\n");
for (int i = 1; i <= 10; i++)
{
SLEEP(1000);
printf("%ds elapsed...\n",i);
}
printf("\nAcquisition ended.\n");
break;
case 'h':
printf("Apply an external start signal at max frequency of 1MHz, and amplitude of 3.3V, and press ENTER when ready.\n");
printf("Note that acquisition will not progress if the signal is not applied or paused.\n");
getchar();
{
SLEEP(100);
if (!err)
{
clear_screen();
printf(" **********************\n");
printf(" * Acquisition status *\n");
printf(" **********************\n");
print_status(status);
printf("External start frequency: %.3f MHz\n", extStartFreq*1e-6);
}
else
printf("\nError %d", err);
}
break;
case 'i':
printf("Camera is now configured for using external gate and time tagging pulses on trigger input.\n");
printf("Apply an external gate signal at max frequency of 100MHz, and amplitude of 3.3V, and press ENTER when ready.\nNote that there are timetags due to detected photons.");
getchar();
{
SLEEP(100);
if (!err)
{
clear_screen();
printf(" **********************\n");
printf(" * Acquisition status *\n");
printf(" **********************\n");
print_status(status);
printf("External gate frequency: %.3f MHz\n", extGateFreq*1e-6);
}
else
printf("\nError %d", err);
}
printf("Now remove gate signal and press ENTER when ready. Note there are no more timetags\n");
getchar();
{
SLEEP(100);
if (!err)
{
clear_screen();
printf(" **********************\n");
printf(" * Acquisition status *\n");
printf(" **********************\n");
print_status(status);
printf("External gate frequency: %.3f MHz\n", extGateFreq*1e-6);
}
else
printf("\nError %d", err);
}
printf("Now apply a 3.3V signal to the trigger input and press ENTER when ready.\nNote that, despite no gate is applied, there are now timetags due to pulses into trigger input.\n");
getchar();
{
SLEEP(100);
if (!err)
{
clear_screen();
printf(" **********************\n");
printf(" * Acquisition status *\n");
printf(" **********************\n");
print_status(status);
printf("External gate frequency: %.3f MHz\n", extGateFreq*1e-6);
printf("Aux (trigger-in) frequency: %.3f MHz\n", extTrigFreq*1e-6);
}
else
printf("\nError %d", err);
}
break;
case 'j':
printf("Camera is now in triggered mode, for each trigger pulse 50 frames will be acquired up to 500 frames.\n");
printf("Acquisition will now start.\n");
printf("Apply single trigger pulses and note that captured frames number increases accordingly, up to 500, and then they are downloaded and decoded.\n");
printf("Press ENTER when ready.\n");
getchar();
{
SLEEP(100);
if (!err)
{
clear_screen();
printf(" **********************\n");
printf(" * Acquisition status *\n");
printf(" **********************\n");
print_status(status);
}
else
printf("\nError %d", err);
}
break;
case 'k':
printf("\nAcquiring data and saving to file acquisition.raw\n");
printf("\nPress ENTER to start the acquisition and then reopen the file.");
getchar();
{
SLEEP(100);
if (!err)
{
clear_screen();
printf(" **********************\n");
printf(" * Acquisition status *\n");
printf(" **********************\n");
print_status(status);
}
else
printf("\nError %d", err);
}
printf("\nRaw file acquisition.raw.dat created. Now closing physical device and opening the file.\n");
crono = NULL;
if (!err) {
printf("\nSUCCESSFUL!\nRaw file acquisition.raw.dat opened.\n");
}
else {
printf("Error %i !\n", err);
loop = 0;
break;
}
printf(
"Acquisition time: %s\n", acqInfo.
DateTime);
printf("\nPress ENTER to start reading the raw file.");
getchar();
{
SLEEP(100);
if (!err)
{
clear_screen();
printf(" **********************\n");
printf(" * Acquisition status *\n");
printf(" **********************\n");
print_status(status);
}
else
printf("\nError %d", err);
}
free(AccHistBuf);
AccHistBuf = (uint32_t*)calloc(4096, sizeof(uint32_t));
total = 0;
{
if (num != 1)
break;
AccHist(HistBuf, AccHistBuf, nPixel);
}
for (int j = 0; j < 4096; j++)
total += AccHistBuf[j];
printf("\nTotal events in histogram: %d\n", total);
crono = NULL;
if (!err) {
printf("\nSUCCESSFUL!\nCamera with serial number %s opened.\n", serial);
}
else {
printf("Error %i !\n", err);
loop = 0;
break;
}
pattern[0] = 0;
pattern[1] = 700;
if (err != 0)
{
loop = 0;
printf("Configuration error!");
}
break;
case 'q':
loop = 0;
break;
}
}
if(crono)
crono = NULL;
free(CntsBuf);
free(HistBuf);
free(AccHistBuf);
printf("Press ENTER to continue\n");
getchar();
return 0;
}
CRONO software development kit.
CRONO_Return CRONO_SaveSettingsToFile(CRONO_H crono, char *path)
Saves current settings to file.
CRONO_Return CRONO_LoadSettingsFromFile(CRONO_H crono, char *path)
Loads Crono settings from a file.
CRONO_Return CRONO_GetCameraSettings(CRONO_H crono, CRONO_CameraSettings *settings)
Gets actual Crono settings and saves them in a user provided CRONO_CameraSettings struct passed by re...
CRONO_Return CRONO_ConfigAcquisition(CRONO_H crono, CRONO_PixelMode pixelMode, cronoBool framesEnable, cronoBool histogramsEnable, cronoBool timeTagsEnable, cronoBool liveEnable, cronoBool unused, const char *rawDataOutPath)
configures the acquisition modes and selects the output data formats.
CRONO_Return CRONO_ConfigSensor(CRONO_H crono, int activePixels, cronoBool half1Enable, cronoBool half2Enable, double *maxFrameStartFrequency)
Configures the Crono spad array sensor region of interest, i.e.
CRONO_Return CRONO_SetSpadDeadTime(CRONO_H crono, int deadTimeNs)
Sets the SPADs dead time in ns.
CRONO_Return CRONO_ConfigTriggerExternal(CRONO_H crono, int framesBurstCount)
Sets the camera in external trigger mode.
CRONO_Return CRONO_ConfigAuxiliaryInputs(CRONO_H crono, CRONO_AuxInputMode bitModeA, CRONO_AuxInputMode bitModeB, double bitAThreshold)
Configure aux inputs sampling.
CRONO_Return CRONO_ConfigGateExternal(CRONO_H crono, double threshold, cronoBool externalGateInvert)
Sets the camera in external gate mode and configure the associated parameters.
CRONO_Return CRONO_GetInputFrequencies(CRONO_H crono, double *extStartFrequency, double *extGateFrequency, double *extTriggerFrequency)
Gets the current meaured input signal frequencies at the SMA inputs.
CRONO_Return CRONO_ConfigOutputs(CRONO_H crono, int chan1Selection, int chan2Selection, int chan3Selection)
Configures which Crono signals are forwarded to each of the three output ports.
CRONO_Return CRONO_ConfigFrameStartExternal(CRONO_H crono, double frameRate, double threshold, cronoBool externalStartPosedge, int divFactor)
Sets the camera in external frame start mode and configure the associated parameters.
CRONO_Return CRONO_ConfigLaserSync(CRONO_H crono, int *pattern, int patternLen)
Configures the pattern of internally generated laser syncronization signal.
CRONO_Return CRONO_ConfigGateInternal(CRONO_H crono, int *pattern, int patternLen)
Set the camera in internal gate mode and configures the pattern of internally generated gate.
CRONO_Return CRONO_ConfigTriggerInternal(CRONO_H crono)
Sets the camera in internal trigger mode.
CRONO_Return CRONO_ConfigFrameStartInternal(CRONO_H crono, double frameRate, double *actualBin)
Sets the camera in internal frame start mode and sets the frame start rate.
CRONO_Return CRONO_Destr(CRONO_H crono)
Frees all resources owned by a Crono handle.
CRONO_Return CRONO_Constr(CRONO_H *crono)
Constructs a new Crono object.
CRONO_Return CRONO_StopAcquisition(CRONO_H crono, cronoBool force)
Stops an ongoing acquisition.
CRONO_Return CRONO_GetHistogramData(CRONO_H crono, uint32_t *buf, uint64_t capacityNumHists, uint64_t *copiedNumHists)
Gets an acquisition data chuck in histogram format.
CRONO_Return CRONO_GetAcquisitionStatus(CRONO_H crono, CRONO_AcquisitionStatus *status)
Gets the current acquisition status.
CRONO_Return CRONO_GetLiveData(CRONO_H crono, uint32_t *countsBuf, uint32_t *histogramBuf, cronoBool *dataIsNew)
Gets latest live data whenever available.
CRONO_Return CRONO_GetFramesData(CRONO_H crono, uint32_t *buf, uint64_t capacityNumFrames, uint64_t *copiedNumFrames)
Gets an acquisition data chuck in frames format.
CRONO_Return CRONO_GetAcquisitionInfo(CRONO_H crono, CRONO_AcquisitionInfo *acqInfo)
Gets informations about the last acquisition.
CRONO_Return CRONO_StartAcquisition(CRONO_H crono, uint64_t acqMaxFrames, int integPeriodFrames)
Starts a new acquisition.
#define MAX_SERIAL_LENGTH
Maximum serial number string length.
Definition: CRONO_SDK.h:87
CRONO_Return CRONO_GetDeviceCount(CRONO_H crono, int *count)
Gets the count of all active and connected Crono devices.
CRONO_Return CRONO_OpenDeviceBySerial(CRONO_H crono, char *serial)
Opens a device with a given serial number.
CRONO_Return CRONO_GetDeviceInfo(CRONO_H crono, char *serial, CRONO_DeviceInfo *deviceInfo)
Gets information about a device with a given serial number, or of the already open device.
CRONO_Return CRONO_GetDeviceSerial(CRONO_H crono, int deviceIndex, char *buf)
Get the serial number of a connected Crono device given its numeric index.
CRONO_Return CRONO_OpenDeviceAsDataConverter(CRONO_H crono, char *rawFilePath)
Open saved Crono raw file as a virtual device for data conversion.
uint64_t acquiredFramesCount
Number of acquired frames.
Definition: CRONO_SDK.h:167
int deadTimeNs
SPAD deadtime in ns.
Definition: CRONO_SDK.h:214
int64_t decodedFrameCount
Number of frames decoded by SDK since acquisition start.
Definition: CRONO_SDK.h:196
cronoBool ongoing
Boolean value that indicates wether the acquisition is ongoing.
Definition: CRONO_SDK.h:206
int64_t hostAllocatedBytes
Current ram usage for storing acquired and decoded data on the host computer.
Definition: CRONO_SDK.h:199
int SdkMinorVersion
SDK minor version.
Definition: CRONO_SDK.h:157
int FwMinorVersion
Firmware minor version.
Definition: CRONO_SDK.h:154
int SdkMajorVersion
SDK major version.
Definition: CRONO_SDK.h:156
int64_t deviceRamUsageBytes
Current usage of Crono device RAM expressed in bytes.
Definition: CRONO_SDK.h:197
int SdkPatchVersion
SDK patch version.
Definition: CRONO_SDK.h:158
int64_t capturedFrameCount
Number of frames captured by the camera since acquisition start.
Definition: CRONO_SDK.h:195
CRONO_SensorType SensorType
Sensor type, 128x1 or 8x8.
Definition: CRONO_SDK.h:151
char DateTime[MAX_DATETIME_LENGTH]
Date and time of acquisition.
Definition: CRONO_SDK.h:166
int64_t availableHistogramCount
Number of currently buffered histograms.
Definition: CRONO_SDK.h:203
int FwPatchVersion
Firmware patch version.
Definition: CRONO_SDK.h:155
int64_t downloadedBytes
Number of downloaded bytes on the host computer since acquisition start.
Definition: CRONO_SDK.h:198
int64_t auxBitBCount
Count of bit B samples>.
Definition: CRONO_SDK.h:205
int64_t availableFramesCount
Number of currently buffered frames.
Definition: CRONO_SDK.h:201
int FwMajorVersion
Firmware major version.
Definition: CRONO_SDK.h:153
int64_t availableTimeTagsCount
Number of currently buffered time tags values.
Definition: CRONO_SDK.h:202
CRONO_PixelMode countingMode
Camera operation mode.
Definition: CRONO_SDK.h:220
double acquisitionTime
Elapsed time in seconds since acquisition start.
Definition: CRONO_SDK.h:194
struct Crono * CRONO_H
Type CRONO_H.
Definition: CRONO_SDK.h:102
CRONO_Return
Error table.
Definition: CRONO_SDK.h:108
uint8_t cronoBool
Type cronoBool.
Definition: CRONO_SDK.h:99
@ RISING_EDGE
Sample the auxiliary input on rising edge.
Definition: CRONO_SDK.h:185
@ OFF
Do not sample the auxiliary input.
Definition: CRONO_SDK.h:184
@ CRONO_8X8
8x8 pixels sensor
Definition: CRONO_SDK.h:143
@ CRONO_128X1
128x1 pixels sensor
Definition: CRONO_SDK.h:144
@ TIMING
Event timing mode.
Definition: CRONO_SDK.h:175
@ COUNTING
Event counting mode.
Definition: CRONO_SDK.h:176
Struct containing information about the acquisition.
Definition: CRONO_SDK.h:165
Struct containing the status of an ongoing Crono acquisition.
Definition: CRONO_SDK.h:193
Struct containing camera settings.
Definition: CRONO_SDK.h:213
Struct containing information about the version and connection speed grade of a connected Crono devic...
Definition: CRONO_SDK.h:150